<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<button id="test">test</button>

<form action="regist" method="post">
	<input type="text" name="id"/>
	<input type="text" name="name"/>
	<input type="submit"/>
</form>
<script type="text/javascript">
	var test=document.getElementById("test");
	test.onclick=function(){
		var xhr=new XMLHttpRequest();
		xhr.open("POST","regist1");
		xhr.setRequestHeader("Content-Type","application/json");
		xhr.setRequestHeader("Accept", "application/json");
		xhr.onreadystatechange=function(){
			if(xhr.readyState==4){
				if(xhr.status==200){
					var u=eval('('+xhr.responseText+')');
					alert(u.uname);
				}
			}		
		};
		var d={id:1,uname:"john2"};
		xhr.send(JSON.stringify(d));
	}
</script>
</body>
</html>